/*
 * LoginPanel.java
 *
 * Created on 2008年5月27日, 下午9:12
 */

package gui;

/**
 *
 * @author  yux
 */
public class OptionUserPanel extends javax.swing.JPanel {
    private MainFrame mf;
    private abstractmodel.IUser ur;
    /** Creates new form LoginPanel */
    public OptionUserPanel(MainFrame m, model.User u) {
        mf = m;
        ur = u;
        initComponents();
        initInfo();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldName = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jComboBoxGender = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jTextFieldPhone = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jPasswordFieldOld = new javax.swing.JPasswordField();
        jPasswordFieldNew = new javax.swing.JPasswordField();
        jPasswordFieldConfirm = new javax.swing.JPasswordField();
        jLabelEmail = new javax.swing.JLabel();

        jLabel1.setFont(new java.awt.Font("宋体", 0, 18));
        jLabel1.setText("用户个人信息");

        jLabel2.setFont(new java.awt.Font("宋体", 0, 14));
        jLabel2.setText("注册邮箱");

        jLabel3.setFont(new java.awt.Font("宋体", 0, 14));
        jLabel3.setText("姓名");

        jLabel4.setFont(new java.awt.Font("宋体", 0, 14));
        jLabel4.setText("性别");

        jComboBoxGender.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel5.setFont(new java.awt.Font("宋体", 0, 14));
        jLabel5.setText("联系电话");

        jLabel6.setFont(new java.awt.Font("宋体", 0, 14));
        jLabel6.setText("修改密码");

        jLabel7.setFont(new java.awt.Font("宋体", 0, 14));
        jLabel7.setText("当前密码");

        jLabel8.setFont(new java.awt.Font("宋体", 0, 14));
        jLabel8.setText("新密码");

        jLabel9.setFont(new java.awt.Font("宋体", 0, 14));
        jLabel9.setText("确认新密码");

        jLabelEmail.setFont(new java.awt.Font("宋体", 0, 14));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(61, 61, 61)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addGap(15, 15, 15)
                                .addComponent(jLabelEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel8)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel9)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel5))
                                .addGap(4, 4, 4)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jTextFieldPhone, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)
                                        .addComponent(jComboBoxGender, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jTextFieldName, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jPasswordFieldOld))
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(jPasswordFieldConfirm, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jPasswordFieldNew, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE))))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(44, 44, 44)
                        .addComponent(jLabel6))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(24, 24, 24)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(145, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(15, 15, 15)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabelEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTextFieldName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBoxGender, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jTextFieldPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(35, 35, 35)
                .addComponent(jLabel6)
                .addGap(36, 36, 36)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jPasswordFieldOld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jPasswordFieldNew, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jPasswordFieldConfirm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(84, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void initInfo() {
        this.jLabelEmail.setText(ur.getUserInfo().getValue("用户名").getString());
        jTextFieldName.setText(ur.getUserInfo().getValue("客户姓名").getString());
        jTextFieldPhone.setText(ur.getUserInfo().getValue("联系电话").getString());
        jComboBoxGender.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "男", "女"}));
        if(ur.getUserInfo().getValue("性别").getString().equals("男"))
            jComboBoxGender.setSelectedIndex(0);
        else
            jComboBoxGender.setSelectedIndex(1);
    }
    
    /**
     * 更改用户密码
     * @param evt
     */    
    public String[] returnValue () {
        //"用户名", "密码", "客户姓名"", "性别", "联系电话"
        String s[] = null;
        String pw = RegisterPanel.char2string(jPasswordFieldOld.getPassword());
        String pwNew = RegisterPanel.char2string(jPasswordFieldNew.getPassword());
        String pwCon = RegisterPanel.char2string(jPasswordFieldConfirm.getPassword());
        if(pw.equals("") && pwNew.equals("") && pwCon.equals("")) {
            s = new String[4];
            s[0]=null;
            s[1] = jTextFieldName.getText();
            s[2] = jComboBoxGender.getSelectedItem().toString();
            s[3] = jTextFieldPhone.getText();
            return s;
        }
        if (Utilities.getMd5(pw).equals(ur.getUserInfo().getValue("密码").getString())
                && pwNew.equals(pwCon)) {
            s = new String[4]; 
            s[0] = pwNew;
            if (pwNew.length() < 6) {
                String[] options = {"确定"};
                javax.swing.JOptionPane.showOptionDialog(null, "请输入长度大于等于6的密码!", 
                    "警告", javax.swing.JOptionPane.DEFAULT_OPTION, 
                    javax.swing.JOptionPane.WARNING_MESSAGE, null, options, options[0]); 
                s[0]=null;
            }

            s[1] = jTextFieldName.getText();
            s[2] = jComboBoxGender.getSelectedItem().toString();
            s[3] = jTextFieldPhone.getText();
        }else {
            s = new String[4];
            s[0]=null;
            s[1] = jTextFieldName.getText();
            s[2] = jComboBoxGender.getSelectedItem().toString();
            s[3] = jTextFieldPhone.getText();
        }
        return s;
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox jComboBoxGender;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLabelEmail;
    private javax.swing.JPasswordField jPasswordFieldConfirm;
    private javax.swing.JPasswordField jPasswordFieldNew;
    private javax.swing.JPasswordField jPasswordFieldOld;
    private javax.swing.JTextField jTextFieldName;
    private javax.swing.JTextField jTextFieldPhone;
    // End of variables declaration//GEN-END:variables
    
}
